<?PHP

require_once WACT_ROOT.'controller/controller.inc.php';

require_once APP_ROOT.'view/pub/layoutright.view.php';
require_once APP_ROOT.'model/common/session.php';
require_once APP_ROOT.'model/common/user.php';
require_once APP_ROOT.'model/common/player.php';
require_once APP_ROOT.'model/common/price.php';
require_once APP_ROOT.'model/common/date.php';
require_once APP_ROOT . "model/common/site.php";



class PlayersDetailView extends LayoutRightView {
	function PlayersDetailView($TemplateFile){
		parent::LayoutRightView($TemplateFile);

	}

	function prepare(&$controller, &$request, &$responseModel){
		parent::prepare(&$controller, &$request, &$responseModel);

		if(APP_NAME!=""){
			$this->Template->set('app_name',APP_NAME);
		} else $this->Template->set('app_name','.');

		if(!Session::isLogin())
			$this->Template->set('login',' ');

		$player_id=$request->getParameter('id');

		$this->Template->set('player_id',$player_id);

		$player=&Player::getRecord($player_id);

		if(Session::isLogin()&&Session::getUserId()==$player->get('user_id'))
			$this->Template->set('author',' ');


		$this->Template->set('SITE_CSS',Site::getSiteTemplateCSS());
		$this->Template->set('SITE_BASE',Site::getSiteTemplateBase());
		$this->Template->set('SITE_TITLE',Site::getTitle());
		$this->Template->set('title',Site::getTitle().' - Player profile - '.$player->get('name'));


		$datestr=$player->get('date_added');
		$mydate=strtotime($datestr);
        $tz =& new MyTimeZone();
        $mydate = $tz->timeGMT($mydate);
		$datestr = gmstrftime('%b %d, %Y',$mydate);
		$this->Template->set('date_added',$datestr);

		$prem = $player->get('premium');
		//$prem = true;
		if($prem && $prem==0) $prem=null;
		if($prem) $this->Template->set('prem',$prem);

		$premiumVideo = $player->get('premiumVideo');
		//print 'Premium Video: '.$premiumVideo;
		if($premiumVideo) $this->Template->set('showPremiumVideoLink',1);

		$this->Template->set('name',$player->get('name'));
		$this->Template->set('class',$player->get('class'));

		// height/weight
		$height=$player->get('height');
		$weight=$player->get('weight');

		if($height) {
			$heightweight=$height.'/';
			if($weight) $heightweight.=$weight;
			$this->Template->set('heightweight',$heightweight);
		}else if($weight) {
			$heightweight='/'.$weight;
			$this->Template->set('heightweight',$heightweight);
		}

		$position=$player->get('position');
		if($position)$this->Template->set('position',$position);

		$category1=$player->get('category1');
		$category2=$player->get('category2');

		//categories
		if($category1) {
			$category=$category1;
			if($category2)	$category.='/'.$category2;
			$this->Template->set('category',$category);
		} else if($category2){
			$this->Template->set('category',$category2);
		}

	/*	$contact_phone=$player->get('contact_phone');
		if($contact_phone && Session::isLogin())
			$this->Template->set('contact_phone',$contact_phone);*/

		//school
		$school=$player->get('school_name');
		if($school)$this->Template->set('school_name',$school);

		$location=null;
		$saddress=$player->get('school_address');
		$scity=$player->get('school_city');
		$sstate=$player->get('school_state');
		$szip=$player->get('school_zip');
		$sphone=$player->get('school_phone');
		if($saddress) {
			$this->Template->set('school_address',$saddress);
			$location=' ';
		}
		if($scity) $location=$scity;
		if($sstate&&$sstate!='(N') $location.=', '.$sstate;
		if($szip) $location.=' '.$szip;
		if($location&&$location!=' ')
			$this->Template->set('school_lastaddress',$location);
		if($sphone) {
			$location='Phone: '.$sphone;
			$this->Template->set('school_phone',$location);
		}
		if($location)$this->Template->set('school_location',true);

		$img=$player->get('photo_url');
		if($img) $this->Template->set('photo_url',$img);

		//coach

		$coach_name=$player->get('coach_name');
		$coach_phone=$player->get('coach_phone');
		if($coach_name){
			$coach=$coach_name;
			if($coach_phone) 	$coach.=', '.$coach_phone;
			$this->Template->set('coach',$coach);
		}

		$gpa=$player->get('gpa');
		if($gpa) $this->Template->set('gpa',$gpa);
		$sat=$player->get('sat');
		if($sat) $this->Template->set('sat',$sat);

		$team=$player->get('team');
		if($team) $this->Template->set('team',$team);

		$projected_level=$player->get('projected_level');
		if($projected_level&&$projected_level!='')
			$this->Template->set('projected_level',$projected_level);
		$why_official_list=$player->get('why_official_list');
		if($why_official_list&&$why_official_list!='')
			$this->Template->set('why_official_list',$why_official_list);
		$description=$player->get('description');
		if($description&& $description!='')
			$this->Template->set('description',$description);

		$interest_offers = $player->get('interest_offers');
        if($interest_offers && $interest_offers != '')
			$this->Template->set('interest_offers',$interest_offers);


        // determine the right to see the page details
        /*
        $showdetail=false;
		if(Session::isLogin()) {
			$user_id=Session::getUserId();
			if(User::isUserSubscriptionActive($user_id)) {
				$showdetail=true;
			}
			else if(User::isUserAdmin($user_id)) {
				$showdetail=true;
			}
			if($player->get('user_id')==$user_id)	$showdetail=true;
		}

        if (!$showdetail)
        {
    		$headline='Interview teaser - '.$headline;
			$teaser=$page->get('teaser');
			$this->Template->set('description',$teaser);

			$price =& Price::getPrice(4);
			$price1 =& Price::getPrice(1);
			$price2 =& Price::getPrice(2);
			$price3 =& Price::getPrice(3);

			$price = number_format($price,2);
			$price1 = number_format($price1,2);
			$price2 = number_format($price2,2);
			$price3 = number_format($price3,2);
			$this->Template->set('price',$price);
			$this->Template->set('price1',$price1);
			$this->Template->set('price2',$price2);
			$this->Template->set('price3',$price3);

			//$price=&Price::getPriceByType(4);
			//$number=$price->get('price');
			//list($int,$dec)=explode('.',$number);
			//if(!($dec>0))
			//		$this->Template->set('price',$int);
			$this->Template->set('forteaser',true);
		}
		*/



	}

}



class PlayersTeaserView extends LayoutRightView {
	function PlayersTeaserView($TemplateFile){
		parent::LayoutRightView($TemplateFile);

	}

	function prepare(&$controller, &$request, &$responseModel){
		parent::prepare(&$controller, &$request, &$responseModel);
		if(!Session::isLogin())
			$this->Template->set('login',' ');

		$player_id=$request->getParameter('id');

		$this->Template->set('player_id',$player_id);

		$player=&Player::getRecord($player_id);

		if(Session::isLogin()&&Session::getUserId()==$player->get('user_id'))
			$this->Template->set('author',' ');



		$this->Template->set('SITE_CSS',Site::getSiteTemplateCSS());
		$this->Template->set('SITE_BASE',Site::getSiteTemplateBase());
		$this->Template->set('SITE_TITLE',Site::getTitle());
		$this->Template->set('title',Site::getTitle().' - Player profile - '.$player->get('name').' - Please subscribe');


		$datestr=$player->get('date_added');
		$mydate=strtotime($datestr);
        $tz =& new MyTimeZone();
        $mydate = $tz->timeGMT($mydate);
		$datestr = gmstrftime('%b %d, %Y',$mydate);
		$this->Template->set('date_added',$datestr);

		$this->Template->set('prem',true);

		$this->Template->set('name',$player->get('name'));
		$this->Template->set('class',$player->get('class'));

		$img=$player->get('photo_url');
		if($img) $this->Template->set('photo_url',$img);

		$description=$player->get('description');
		if($description&& $description!='')
			$this->Template->set('description',$description);

			//price per year
		//$price =& Price::getPrice(4);
		//$price = number_format($price,2);
			$price =& Price::getPrice(4);
			$price1 =& Price::getPrice(1);
			$price2 =& Price::getPrice(2);
			$price3 =& Price::getPrice(3);

			$price = number_format($price,2);
			$price1 = number_format($price1,2);
			$price2 = number_format($price2,2);
			$price3 = number_format($price3,2);
			$this->Template->set('price',$price);
			$this->Template->set('price1',$price1);
			$this->Template->set('price2',$price2);
			$this->Template->set('price3',$price3);


		//$number=$price->get('price');
		//list($int,$dec)=explode('.',$number);
		//if(!($dec>0))
		//$this->Template->set('price',$price);

        if(APP_NAME!=""){
			$this->Template->set('app_name',APP_NAME);
		} else $this->Template->set('app_name','.');
	}

}


class PlayersDetailPage extends PageController{
	function PlayersDetailPage(){
		parent::PageController();

		$showdetail=false;


		$player_id=Request::getParameter('id');
		$player =& Player::getRecord($player_id);

		$premium = $player->get('premium');
		//$premium = true;

		if(!$premium) $showdetail=true;
        else if(Session::isLogin()){
			$user_id=Session::getUserId();
			if(User::isUserSubscriptionActive($user_id)){
				$showdetail=true;
			}
			else if(User::isUserAdmin($user_id)){
				$showdetail=true;
			}

			if($player->get('user_id')==$user_id) $showdetail=true;
		}

        $site_id = Site::getTemplateSiteID();
        $mytemplate1 = 'pub/players/detail.html';
        $mytemplate2 = 'pub/players/teaser.html';

		if($showdetail)
			$this->setDefaultView(new PlayersDetailView($mytemplate1));
		else
			$this->setDefaultView(new PlayersTeaserView($mytemplate2));
	}


}

?>
